package com.example.testsqlite;

import android.app.Fragment;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class AttributeFragmnet extends Fragment{
	String[] attributes;
	String tableName;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(this.getArguments() != null){
			tableName = this.getArguments().getString("table");		
			Log.i("gjf", "AttributeFragmnet getArguments()");
		}	
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View attributeView = inflater.inflate(R.layout.show_content_attribute, container,false);
		ListView listAttribute =  (ListView)attributeView.findViewById(R.id.listView_attributes);
		
		attributes = new String[3]; 
		Cursor cursorAttribute = MainActivity.sqliteDatabase.rawQuery(
						"select * from " + tableName, null);
		Log.i("gjf", "getWritableDatabase().rawQuery(" + cursorAttribute.getCount());
		cursorAttribute.moveToFirst();
		Log.i("gjf", "cursorAttribute.moveToFirst();");
		while (!cursorAttribute.isAfterLast()) {
			Log.i("gjf", "while (!cursorAttribute.isAfterLast()) ");
			attributes[0] = (cursorAttribute.getString(1));
			attributes[1] = (cursorAttribute.getString(2));
			attributes[2] = (cursorAttribute.getString(3));
		}
			
		listAttribute.setAdapter(new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, attributes));
		return attributeView;
		
	}
}
